<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Node_Entity extends CI_Model
{
    private $tablename = 'node';
    private $nid = null;
    private $vid = null;
    private $type = null;
    private $language = null;
    private $title = null;
    private $uid = null;
    private $status = null;
    private $created = null;
    private $changed = null;
    private $comment = null;
    private $promote = null;
    private $sticky = null;
    private $tnid = null;
    private $translate = null;
    
    public function setNid($Nid)
    {
        $this->nid = $Nid;
    }

    public function setVid($Vid)
    {
        $this->vid = $Vid;
    }

    public function setType($Type)
    {
        $this->type = $Type;
    }

    public function setLanguage($Language)
    {
        $this->language = $Language;
    }

    public function setTitle($Title)
    {
        $this->title = $Title;
    }

    public function setUid($Uid)
    {
        $this->uid = $Uid;
    }

    public function setStatus($Status)
    {
        $this->status = $Status;
    }

    public function setCreated($Created)
    {
        $this->created = $Created;
    }

    public function setChanged($Changed)
    {
        $this->changed = $Changed;
    }

    public function setComment($Comment)
    {
        $this->comment = $Comment;
    }

    public function setPromote($Promote)
    {
        $this->promote = $Promote;
    }

    public function setSticky($Sticky)
    {
        $this->sticky = $Sticky;
    }

    public function setTnid($Tnid)
    {
        $this->tnid = $Tnid;
    }

    public function setTranslate($Translate)
    {
        $this->translate = $Translate;
    }

    public function save()
    {
        $params = array();
        foreach ($this as $key => $val) {
            if ($key == 'tablename') continue;
            if ($val === null || $val === '') continue;
            $params[$key] = $val;
        }
                
        if (!isset($params['id'])) {
            if ($this->db->insert($this->tablename, $params)) {
                return $this->db->insert_id();
            } else {
                return 0;
            }
        } else {
            return $this->db->update($this->tablename, $params, array('id' => $params['id']));
        }
        
    }
    
    public function del($id)
    {
        
        return $this->db->delete($this->tablename, array('id' => $id));    
    }
    
    public function getNodeById($id)
    {
        $query = $this->db->get_where($this->tablename, array('id' => $id));
        if ($query->num_rows() > 0) {
            return $query->row();
        }
        return false;
    }
    
    public function getAllList()
    {
        $query = $this->db->get($this->tablename);
        return $query->result();
    }
    
    public function TotalNode()
    {
        $query = $this->db->count_all_results('Node'); 
        return $query->result();
    } 
}       
        